from django.views import View
from django.shortcuts import render

from .models import Exercise, Question
from course.models import Course


class ExerciseListView(View):

    def get(self, request, course_id):
        course = Course.objects.get(pk=course_id)
        exercises = Exercise.objects.filter(course_id=course_id)
        return render(
            request,
            'exercise/list.html',
            {
                'exercises': exercises,
                'course': course
            }
        )


class ExerciseDetailView(View):
    def get(self, request, course_id, exercise_id):
        course = Course.objects.get(pk=course_id)
        questions = Question.objects.filter(exercise_id=exercise_id)
        return render(
            request,
            'exercise/detail.html',
            {
                'course': course,
                'questions': questions,
            }
        )
